--违心积压
local weixingjiya = fk.CreateSkill {
    name = "mcdh_weixingjiya",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

weixingjiya:addEffect(fk.Damaged,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
            return p:canMoveCardsInBoardTo(player) end), Util.IdMapper)
        if #targets == 0 then
            player:drawCards(1,self.name)
        else
            local tos = room:askToChoosePlayers(player,{
                targets = targets,
                min_num = 1,
                max_num = 1,
                prompt = "#weixingjiya-choose",
                skill_name = self.name,
                cancelable = false
              })
            local to = tos[1]
            if to then
                local result = room:askForMoveCardInBoard(player, to, player, self.name, nil, to)
                if result.card.sub_type == Card.SubtypeDelayedTrick then
                    player:drawCards(1,self.name)
                end
            end
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_weixingjiya"] = "违心积压",
    [":mcdh_weixingjiya"] ="当你受到伤害后,你将场上一张牌移动至你的对应区域内，若无法执行或移动了延时锦囊牌，你摸一张牌。",
    ["#weixingjiya-choose"] = "违心积压:将场上一张牌移动至你的对应区域内",
}

return weixingjiya